import moment from 'moment';
//金额,数字格式化
export const number_format = (number, decimals, dec_point, thousands_sep) =>{
    /*
　　 * 参数说明：
    * number：要格式化的数字
    * decimals：保留几位小数
    * dec_point：小数点符号
    * thousands_sep：千分位符号
    * */
    number = (number + '').replace(/[^0-9+-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number;
  var   prec = !isFinite(+decimals) ? 2 : Math.abs(decimals);
  var   sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
  var    dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
  var    s = '';

    s = (prec ? n.toFixed(prec) : '' + Math.round(n)).split('.');
    var re = /(-?\d+)(\d{3})/;
    while(re.test(s[0])) {
        s[0] = s[0].replace(re, "$1" + sep + "$2");
    }

    if((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
};
export const datatimeformat = (time) => {
    if(!time){
        return time;
    }
    return new moment(time).format("YYYY-MM-DD HH:mm:ss")
};
//日期格式化，自定义日期，时间分隔符
export const dataTimeFormatCustomSep = (time,dateSep,timeSep) => {
    if(!time){
        return time;
    }
    return new moment(time).format("YYYY" + dateSep + "MM" + dateSep +  "DD HH" + timeSep + "mm"+ timeSep + "ss")
};
export const datetime_noconnection_format = (time) => {
    if(!time){
        return time;
    }
    return new moment(time , "YYYYMMDDHHmmss").format("YYYY-MM-DD HH:mm:ss")
    // return new moment(time).format("YYYYMMDDHHmmss")
};

export const datatimeformat2 = (time) => { //没有秒
    if (time != null)
        return new moment(time).format("YYYY-MM-DD HH:mm")
};

//日期格式化
export const dataformatYMD = (time) => {
    if (time != null)
        return new moment(time).format("YYYY-MM-DD")
};

export const datatimeformatday = (time) => {
    if (time != null)
        return new moment(time).format("YYYY-MM-DD")
};
//日期格式化
function data_format(time) {
    if (time != null)
        return new moment(time).format("YYYY-MM-DD")
}
//时间格式化
function date_time_format(time) {
    if (time != null)
        return new moment(time).format("YYYY-MM-DD HH:mm:ss")
}

//时间格式化
function time_format(time) {
    if (time != null)
        return new moment(time).format("HH:mm")
}
       
/**
 * 支付状态
 * @param rechargePaymethod
 * @returns {string}
 */
export const recharge_status = (rechargeStatus) => {
    var rechargeStatusStr="";
    switch (rechargeStatus) {
        case 0:
            rechargeStatusStr="未确认";
            break;
        case 1:
            rechargeStatusStr="未支付";
            break;
        case 2:
            rechargeStatusStr="已支付";
            break;
        case 3:
            rechargeStatusStr="支付失败";
            break;
        case 4:
            rechargeStatusStr="已作废";
            break;
        case 5:
            rechargeStatusStr="已退款";
            break;
    }
    return rechargeStatusStr;
};
 

//性别过滤
export const sex_filter = (sex) => {
    var sexName = '';
    switch (sex) {
        case 0:
            sexName = '未知';
            break;
        case 1:
            sexName = '男';
            break;
        case 2:
            sexName = '女';
            break;
    }
    return sexName;
};

//实名认证状态
export const certification_status = (certificationStatus) => {
    var certificationStatusName = '';
    switch (certificationStatus) {
        case 0:
            certificationStatusName = '未实名';
            break;
        case 1:
            certificationStatusName = '已实名';
            break;
    }
    return certificationStatusName;
};

//资源状态
export const resource_status = (resourceStatus) => {
    var resourceStatusName = '';
    switch (resourceStatus) {
        case -1:
            resourceStatusName = '删除';
            break;
        case 0:
            resourceStatusName = '禁用';
            break;
        case 1:
            resourceStatusName = '正常';
            break;
        
    }
    return resourceStatusName;
};

//资源类型
export const resource_type = (resourceType) => {
    var resourceTypeName = '';
    switch (resourceType) {
        case 1:
            resourceTypeName = '菜单';
            break;
        case 2:
            resourceTypeName = '功能';
            break;
        case 3:
            resourceTypeName = '按钮';
            break;
        case 4:
            resourceTypeName = '图标';
            break;
        case 5:
            resourceTypeName = '分组';
            break;
    }
    return resourceTypeName;
};
  
        
//车辆默认
export const yesOrNo = (vehicleIsdefault) => {
    var vehicleIsdefaultName = '';
    switch (vehicleIsdefault) {
        case 0:
            vehicleIsdefaultName = '否';
            break;
        case 1:
            vehicleIsdefaultName = '是';
            break;
    }
    return vehicleIsdefaultName;
};

     
/**
 * 充值支付方式
 * @param payMethod
 * @returns {string}
 */
export const pay_method = (payMethod) => {
    var payMethodStr="";
    switch (payMethod) {
        case 0:
            payMethodStr="后台";
            break;
        case 1:
            payMethodStr="微信支付";
            break;
        case 2:
            payMethodStr="支付宝";
            break;
    }
    return payMethodStr;
};

/**
 * 充值支付状态
 * @param payStatus
 * @returns {string}
 */
export const pay_status = (payStatus) => {
    var payStatuStr="";
    switch (payStatus) {
        case 0:
            payStatuStr="未支付";
            break;
        case 1:
            payStatuStr="已支付";
            break;
        case 2:
            payStatuStr="支付失败";
            break;
    }
    return payStatuStr;
};
 

//将秒转换成几天几小时几分钟
export const mToStr = (value) =>{
  var theTime = parseInt(value);// 秒
  var theTime1 = 0;// 分
  var theTime2 = 0;// 小时
  if (theTime > 60) {
    theTime1 = parseInt(theTime / 60);
    theTime = parseInt(theTime % 60);
    if (theTime1 > 60) {
      theTime2 = parseInt(theTime1 / 60);
      theTime1 = parseInt(theTime1 % 60);
    }
  }
  var result = "" + parseInt(theTime) + "秒";
  if (theTime1 > 0) {
    result = "" + parseInt(theTime1) + "分" + result;
  }
  if (theTime2 > 0) {
    result = "" + parseInt(theTime2) + "小时" + result;
  }
  return result;
}
 

export const convertToChinaNum = (num) => {
    var arr1 = new Array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
    var arr2 = new Array('', '十', '百', '千', '万', '十', '百', '千', '亿', '十', '百', '千','万', '十', '百', '千','亿');//可继续追加更高位转换值
    if(!num || isNaN(num)){
        return "零";
    }
    var english = num.toString().split("")
    var result = "";
    for (var i = 0; i < english.length; i++) {
        var des_i = english.length - 1 - i;//倒序排列设值
        result = arr2[i] + result;
        var arr1_index = english[des_i];
        result = arr1[arr1_index] + result;
    }
    //将【零千、零百】换成【零】 【十零】换成【十】
    result = result.replace(/零(千|百|十)/g, '零').replace(/十零/g, '十');
    //合并中间多个零为一个零
    result = result.replace(/零+/g, '零');
    //将【零亿】换成【亿】【零万】换成【万】
    result = result.replace(/零亿/g, '亿').replace(/零万/g, '万');
    //将【亿万】换成【亿】
    result = result.replace(/亿万/g, '亿');
    //移除末尾的零
    result = result.replace(/零+$/, '')
    //将【零一十】换成【零十】
    //result = result.replace(/零一十/g, '零十');//貌似正规读法是零一十
    //将【一十】换成【十】
    result = result.replace(/^一十/g, '十');
    return result;
}
 
